package com.miyake.loveviewweb.client.viewer;

import com.google.gwt.user.client.ui.Composite;
import com.miyake.loveviewweb.client.DataServiceWrapper;
import com.miyake.loveviewweb.client.dialog.BasicDialog;
import com.miyake.loveviewweb.client.dialog.IDialogCreator;
import com.miyake.loveviewweb.client.editor.ArrayEditor;

public class DataDialogCreator implements IDialogCreator {
    private DataServiceWrapper serviceWrapper = DataServiceWrapper.getInstance();
    private EditType editType;
    
    public enum EditType {
        CREATE, UPDATE
    }
    public DataDialogCreator(EditType editType) {
        this.editType = editType;
    }
    
    public void show(String defaultName) {
        if (editType.equals(EditType.CREATE)) {
            new BasicDialog(new ArrayEditor(defaultName)) {   
                @Override
                protected void onOK(Composite composite) {
                    String name = ((ArrayEditor)composite).getText();
                    String text = ((ArrayEditor)composite).getTextData();
                    serviceWrapper.createData(name, text, serviceWrapper.getSelectedFolder().getKey());
                }
            }.showDialog();
        }
        else {
            new BasicDialog(new ArrayEditor()) {
                @Override
                protected void onCancel() {

                }

                @Override
                protected void onOK(Composite composite) {

                }
            }.showDialog(); 
        }
    }

}
